<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>--%>
<%
    String basePath = "http://192.168.1.120:8050/empMaven/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title>注册</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <script type="text/javascript" src="js/jquery-2.1.4.js"></script>
</head>
<body>
    <form action="user/regUser" method="post">
        用户名:<input type="text" name="name" id="name"><font id="nameFont" size="1"></font><p/>
        密码:<input type="password" name="pwd"><p/>
        再输密码:<input type="password" name="pwdTwo"><p/>
        <input type="submit" value="注册">
    </form>
</body>
<script type="text/javascript">
    $("#name").blur(function(){
        //发送ajax请求
        $.ajax({
            //发送该ajax请求的请求方法
            type:"post",//restFUL
            //预计服务器返回的数据格式
            dataType:"json",
            //该请求的地址
            url:"user/regName",
            //需要发送的数据,是json
            data:{"name":$("#name").val()},
            //如果请求以及响应都成功那么执行这里的业务逻辑
            success:function(data){
               if(data.result){
                    $("#nameFont").text("可以注册").css("color","blue")
               }else{
                   $("#nameFont").text("该用户名已经被注册").css("color","red")
               }
            },
            //如果请求失败执行该业务逻辑
            error:function(data){
                alert("请求失败....")
            }
        });
    });
</script>
</html>